package hoowin.basic.model;

import hoowin.basic.service.UserPool;

import java.util.Locale;

public class User extends ModelBase {
	private static final long serialVersionUID = 799168524482208427L;
	
	private UserPool up;
	
	private Account account;
	private boolean online;
	private App defaultApp;
	private String name;
	private String gender;
	private Locale locale;
	private String avatar;
	private String words;
	private int parentId;
	
	public void setUp(UserPool up) {
		this.up = up;
	}
	public UserPool getUp(){
		return this.up;
	}
	public void login(User user, Account account){
		this.account = account;
		setId(user.getId());
		this.online = true;
		this.defaultApp = user.getDefaultApp();
		this.name = user.getName();
		this.gender = user.getGender();
		this.locale = user.getLocale();
		this.avatar = user.getAvatar();
		this.words = user.getWords();
		this.parentId = user.getParentId();
		up.addUser(this);
	}
	public void destroy(){
		if(getId()>0){
			up.removeUser(this);
			setId(0);
			this.online = false;
		}
	}
	public void setDefaultApp(App defaultApp) {
		this.defaultApp = defaultApp;
	}
	public App getDefaultApp() {
		return defaultApp;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public String getGender() {
		return gender;
	}
	public void setLocale(Locale locale) {
		this.locale = locale;
	}
	public Locale getLocale() {
		return locale;
	}
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
	public String getAvatar() {
		return avatar;
	}
	public void setWords(String words) {
		this.words = words;
	}
	public String getWords() {
		return words;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	public Account getAccount() {
		return account;
	}
	public void setOnline(boolean online) {
		this.online = online;
	}
	public boolean getOnline() {
		return online;
	}
	public User getParent() {
		return this.up.getUserById(parentId);
	}
	public void setParentId(int parentId) {
		this.parentId = parentId;
	}
	public int getParentId() {
		return parentId;
	}
}
